package com.lizhangjun.controller;


import com.lizhangjun.domain.QCarousel;
import com.lizhangjun.entity.Result;
import com.lizhangjun.service.QCarouselService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lizhangjun
 * @since 2021-06-23
 */
@Api(tags = {"轮播图相关接口"} )
@RestController
@RequiredArgsConstructor
@RequestMapping("/q-carousel")
public class QCarouselController {

    private final QCarouselService carouselService;

    /**
     * 添加轮播图
     * @param carousel 轮播图
     * @return 是否添加成功
     */
    @ApiOperation("添加轮播图")
    @PostMapping("/add")
    public Result add(@RequestBody QCarousel carousel){
        if(carouselService.saveOrUpdate(carousel)){
            return Result.success();
        }else{
            return Result.fail("添加轮播图失败");
        }
    }

    /**
     * 查找轮播图
     * @return 轮播图
     */
    @ApiOperation("查询轮播图")
    @GetMapping("/list")
    public Result list(){
        return Result.success(carouselService.list());
    }

}

